import { ItemData } from "../Data/Level/ItemData";
import AssetsManager from "../Manager/AssetsManager";
import Board from "./Board";

const { ccclass, property } = cc._decorator;

/**卡片 */
@ccclass
export default class Card extends cc.Component {
    @property({ type: cc.Sprite })
    public Sprite_bg: cc.Sprite = null;
    @property({ type: cc.Sprite })
    public Sprite_icon: cc.Sprite = null;
    @property({ type: cc.Node })
    public cover: cc.Node = null;

    id = 0;
    is装填 = false;

    /**层 */
    // card_layer: number = 1;

    isCover: boolean = false;
    board: Board = null;

    onLoad() {

    }

    Init(x, y, _id: number, _board: Board) {
        this.id = _id;
        this.board = _board;

        this.Refresh();
    }

    Refresh() {
        this.RefreshIcon();
        this.cover.active = this.isCover;
    }

    async RefreshIcon() {
        this.Sprite_icon.node.active = true;

        const item_data = ItemData[this.id];
        this.Sprite_icon.node.active = true;
        this.Sprite_icon.spriteFrame = AssetsManager.图片[item_data.icon];
        this.Sprite_icon.sizeMode = cc.Sprite.SizeMode.TRIMMED;
        this.Sprite_icon.node.scale = 0.5;
    }
}